package cn.buk.tms.entity.bill;

import cn.buk.common.util.DecimalUtil;
import cn.buk.common.util.DateUtil;
import cn.buk.tms.entity.misc.Customer;
import com.fasterxml.jackson.annotation.JsonFormat;

import java.util.Date;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.NamedQueries;
import jakarta.persistence.NamedQuery;
import jakarta.persistence.Table;
import jakarta.persistence.Temporal;
import jakarta.persistence.TemporalType;

/**
 * 酒店预订记录
 * Created by yfdai on 2017/7/16.
 */
@NamedQueries({
        @NamedQuery(
                name = "BillHotelBooking.searchMonthly",
                query = "select new cn.buk.tms.dto.ReportHotelDto(" +
                        "o.hotelName, o.roomType, o.ddate, o.leaveDate, o.roomCount, o.totalAmount, o.totalCost, o.profit," +
                        "b.opDate,b.op1, b.op2, b.op3, " +
                        "b.customerType, o.customerId, b.id, b.supplier, b.paymentMethod) " +
                        "from BillHotelBooking o left join BillInfo b on (o.billNum = b.billNum and o.enterpriseId = b.enterpriseId) " +
                        " where o.enterpriseId = :enterpriseId and b.opDate >= :beginDate and b.opDate <= :endDate " +
                        " order by b.opDate, o.hotelName"
        )
})
@Entity
@Table(name = "hotel_booking")
public class BillHotelBooking {

    @Id
    @GeneratedValue(strategy= GenerationType.IDENTITY)
    private int id;

    @Column(name = "enterprise_id")
    private int enterpriseId;

    /**
     * 为该客户预定的酒店
     */
    @ManyToOne
    @JoinColumn(name="customer_id")
    private Customer customer;

    @Column(name = "customer_id", insertable = false, updatable = false)
    private Integer customerId;

    /**
     * 成本中心
     */
    @Column(name = "cost_center", length = 50)
    private String costCenter;

    @Column(name = "project_name", length = 50)
    private String projectName;


    /**
     * 账单号
     */
    @Column(name = "bill_num")
    private String billNum;

    /**
     * 销售日期
     */
    @JsonFormat(pattern = "yyyy-MM-dd",timezone="GMT+8")
    @Temporal(TemporalType.DATE)
    @Column(name="sale_date")
    private Date saleDate;

    /**
     * 付款方式
     */
    @Column(length = 2)
    private String payMode = "8";



    //姓名 入住日期 酒店名称 房型 价格 服务费

    /**
     * 姓名
     */
    @Column(name="psg_name", length=50)
    private String passengerName;

    /**
     * 酒店名称
     */
    @Column(name="hotel_name", length=50)
    private String hotelName;

    /**
     * 房型
     */
    @Column(name = "room_type", length=50)
    private String roomType;

    @Column(name = "room_count")
    private Integer roomCount;

    /**
     * 入住日期
     */
    @JsonFormat(pattern = "yyyy-MM-dd",timezone="GMT+8")
    @Temporal(TemporalType.DATE)
    private Date ddate;

    /**
     * 离店日期
     */
    @JsonFormat(pattern = "yyyy-MM-dd",timezone="GMT+8")
    @Temporal(TemporalType.DATE)
    @Column(name = "leave_date")
    private Date leaveDate;

    /**
     * 价格/间夜
     */
    private double price;

    /**
     * 底价/间夜
     */
    @Column(name = "bottom_price")
    private Double bottomPrice;

    /**
     * 服务费(目前保存的是总服务费）
     */
    @Column(name = "service_charge")
    private double serviceCharge;

    /**
     * 间夜数
     */
    private Integer count;

    /**
     * 实收客户总额
     */
    @Column(name = "total_amount")
    private Double totalAmount;

    /**
     * 总成本
     */
    @Column(name = "total_cost")
    private Double totalCost;

    /**
     * 利润
     */
    private Double profit;

    private String remark;

    /**
     * 是否已付款
     */
    @Column(name = "be_paid", length = 1)
    private String bePaid;


    /**
     * 保存数据库的时间：系统自动生成
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone="GMT+8")
    @Temporal(TemporalType.TIMESTAMP)
    @Column(name="create_time", insertable = false, updatable = false)
    private Date createTime;


    public String getHotelBookingDetail() {
        return this.hotelName + " " + DateUtil.formatDate(this.ddate, "yyyy-MM-dd") + " " + this.roomType;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public int getEnterpriseId() {
        return enterpriseId;
    }

    public void setEnterpriseId(int enterpriseId) {
        this.enterpriseId = enterpriseId;
    }

    public Customer getCustomer() {
        return this.customer == null ? new Customer() : this.customer;
    }

    public void setCustomer(Customer customer) {
        this.customer = customer;
    }

    public String getBillNum() {
        return billNum;
    }

    public void setBillNum(String billNum) {
        this.billNum = billNum;
    }

    public Date getSaleDate() {
        return saleDate;
    }

    public void setSaleDate(Date saleDate) {
        this.saleDate = saleDate;
    }

    public String getPayMode() {
        return payMode;
    }

    public void setPayMode(String payMode) {
        this.payMode = payMode;
    }

    public String getPassengerName() {
        return passengerName;
    }

    public void setPassengerName(String passengerName) {
        this.passengerName = passengerName;
    }

    public Date getDdate() {
        return ddate;
    }

    public void setDdate(Date ddate) {
        this.ddate = ddate;
    }

    public double getPrice() {
        return price;
    }

    public void setPrice(double price) {
        this.price = price;
    }

    public double getServiceCharge() {
        return serviceCharge;
    }

    public void setServiceCharge(double serviceCharge) {
        this.serviceCharge = serviceCharge;
    }

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    public String getRemark() {
        return remark == null ? "": remark.trim();
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }

    public void setHotelName(String hotelName) {
        this.hotelName = hotelName;
    }

    public void setRoomType(String roomType) {
        this.roomType = roomType;
    }

    public String getRoomType() {
        return roomType == null ? "": roomType.trim();
    }

    public String getHotelName() {
        return hotelName == null ? "": hotelName.trim();
    }

    public String getBePaid() {
        return bePaid;
    }

    public void setBePaid(String bePaid) {
        this.bePaid = bePaid;
    }

    public int getRoomCount() {
        return roomCount == null ? 1: roomCount;
    }

    public void setRoomCount(Integer roomCount) {
        this.roomCount = roomCount;
    }

    public Date getLeaveDate() {
        return leaveDate;
    }

    public void setLeaveDate(Date leaveDate) {
        this.leaveDate = leaveDate;
    }

    public String getCostCenter() {
        return costCenter;
    }

    public void setCostCenter(String costCenter) {
        this.costCenter = costCenter;
    }

    public String getProjectName() {
        return projectName;
    }

    public void setProjectName(String projectName) {
        this.projectName = projectName;
    }

    public double getBottomPrice() {
        return bottomPrice == null ? 0 : bottomPrice;
    }

    public void setBottomPrice(Double bottomPrice) {
        this.bottomPrice = bottomPrice;
    }

    public int getCount() {
        return count == null ? 1 : count;
    }

    public void setCount(Integer count) {
        this.count = count;
    }

    public double getTotalAmount() {
        return totalAmount == null ? 0 : totalAmount;
    }

    public void setTotalAmount(Double totalAmount) {
        this.totalAmount = totalAmount;
    }

    public double getTotalCost() {
        return totalCost == null ? 0 : totalCost;
    }

    public void setTotalCost(Double totalCost) {
        this.totalCost = totalCost;
    }

    public double getProfit() {
        if (this.profit == null) {
          return 0.0;
        }

        return DecimalUtil.keepScale2(this.profit);
    }

    public void setProfit(Double profit) {
        this.profit = profit;
    }

    public Integer getCustomerId() {
        return customerId;
    }

    public void setCustomerId(Integer customerId) {
        this.customerId = customerId;
    }
}
